package com.ruoyi.pay.service.impl;

import com.repair.api.pay.request.PayQueryPageRequest;
import com.repair.api.pay.request.PayQueryRequest;
import com.repair.api.pay.request.param.PayQueryParam;
import com.repair.api.pay.response.PayQueryResponse;
import com.repair.api.pay.response.vo.PaymentInfoVO;
import com.repair.api.pay.service.PaymentFacadeService;
import com.repair.base.exception.BizErrorCode;
import com.repair.base.exception.BizException;
import com.repair.base.response.PageResponse;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.pay.service.PayService;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author chunyu
 * @since 2024/10/20,18:52
 */
@Slf4j
@Service
public class PayServiceImpl implements PayService {

    @DubboReference
    private PaymentFacadeService paymentFacadeService;

    @Override
    public TableDataInfo getPayList(PayQueryParam param) {
        log.debug("分页查询支付单 parma:{}", param);
        PayQueryPageRequest<PayQueryParam> request = new PayQueryPageRequest<>();
        request.setData(param);
        request.setCurrentPage(param.getCurrentPage());
        request.setPageSize(param.getPageSize());
        PageResponse<PaymentInfoVO> response = paymentFacadeService.getPaymentInfoList(request);
        if (!response.getSuccess()) {
            throw new BizException(BizErrorCode.REMOTE_CALL_RESPONSE_IS_FAILED);
        }
        TableDataInfo tableDataInfo = new TableDataInfo();
        tableDataInfo.setRows(response.getData());
        tableDataInfo.setTotal(response.getTotal());
        return tableDataInfo;
    }

    @Override
    public PaymentInfoVO getPayDetail(String payOrderNum) {
        log.debug("查询支付单详情 payOrderNum:{}", payOrderNum);
        PayQueryRequest request = new PayQueryRequest(payOrderNum);
        PayQueryResponse<PaymentInfoVO> response = paymentFacadeService.getPaymentDetail(request);
        if (!response.getSuccess()) {
            throw new BizException(BizErrorCode.REMOTE_CALL_RESPONSE_IS_FAILED);
        }
        return response.getData();
    }

}
